package com.jamila.scancode.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jamila.scancode.entity.User;
import com.jamila.scancode.mapper.UserMapper;
import com.jamila.scancode.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author JAMILA
 * @since 2024-03-31 12:33:18
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public void saveData(User user) {
        QueryWrapper<User> wrapper=new QueryWrapper<>();
        wrapper.eq("tel",user.getTel());
        User user1 = baseMapper.selectOne(wrapper);
        if (user1==null){
            baseMapper.insert(user);
        }else {
            baseMapper.updateById(user);
        }
    }

    @Override
    public boolean updateStatus(String tel, Integer status) {
        QueryWrapper<User> wrapper=new QueryWrapper<>();
        wrapper.eq("tel",tel);
        User user = baseMapper.selectOne(wrapper);
        if (user==null){
            return false;
        }
        user.setStatus(status);
        int update = baseMapper.updateById(user);
        return update>0;
    }
}
